/*
 *  $Id: Charge.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Light.Spells {
    public class Charge: TargetEnchantmentCard<Creature> {
        public Charge(): base("001_l_s_charge") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Light;
            Value = 100;
            Target = CreatureTarget.Both;
            AddManaCost(ElementType.Light, 3);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new ChargeAffect();
        }

        private class ChargeAffect: EnchantmentAffect<Charge> {
            public ChargeAffect() {
                Add(new TimeAffect(4));
            }

            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnBeforeDamage += Damage;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnBeforeDamage -= Damage;
            }

            private static void Damage(AbstractObject target, DamageInfo damage) {
                Creature cr = target as Creature;
                if (cr == null || cr.State != CreatureState.Offence) return;
                if (damage.DmgType != DamageType.PhysicalAttack || damage.HealthChange <= 0) return;
                target.AddAffect(new Affects.Wound(damage.HealthChange));
                damage.HealthChange = 0;
            }
        }
    }
}
